package com.yingxin.yx.framework.commons.helper;

import com.yingxin.yx.framework.commons.exception.BizException;
import org.apache.commons.lang3.StringUtils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Instant;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;

/**
 * 时间工具类
 */

public class DateHelper {

    public static String YYYYMMDDHHMMSS = "yyyy-MM-dd HH:mm:ss";

    public static String YYYYMMDDHHMM = "yyyy-MM-dd HH:mm";

    public static String YYYYMMDD = "yyyy-MM-dd";

    public static String YYYYMM = "yyyy-MM";

    private static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    private static SimpleDateFormat simpleDateFormatyyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");

    private static SimpleDateFormat simpleDateFormatyyyyMM = new SimpleDateFormat("yyyy-MM");

    private static SimpleDateFormat simpleDateFormatyyyy = new SimpleDateFormat("yyyy");

    private static SimpleDateFormat simpleDateFormatMM = new SimpleDateFormat("MM");

    public static long getUnix(Date date){
        return date.getTime() / 1000;
    }

    /**
     * 获取两个日期(yyyy-MM)中间的月份日期集合,包含开始日期月份和结束日期月份
     */
    public static List<String> getIntermediateMonth(String startDate, String endDate){
        List<String> days = new ArrayList<String>();
        Calendar startTime = Calendar.getInstance();
        Calendar endTime = Calendar.getInstance();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
        try {
            //将开始日期设置给calendar
            startTime.setTime(sdf.parse(startDate));
            startTime.add(Calendar.MONTH,-1);//月份减1，包含开始日期月份

            //将结束日期设置给calendar
            endTime.setTime(sdf.parse(endDate));
            while (startTime.before(endTime)){
                startTime.add(Calendar.MONTH,1);
                days.add(sdf.format(startTime.getTime()));
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return days;
    }

    /**
     * 获取当前时间 年-月开始时间
     * @return
     */
    public static String getYearMonthEnd(){
        Date date = new Date();
        return simpleDateFormatyyyyMM.format( date );
    }

    /**
     * 获取当前时间 前12个月 年-月结束时间
     * @return
     */
    public static String getYearMonthBegin(){
        Date date = new Date();
        Calendar calendar = new GregorianCalendar();
        calendar.clear();
        calendar.setTime( date );
        calendar.add( Calendar.MONTH, 0 - 12 );
        return simpleDateFormatyyyyMM.format( calendar.getTime() );
    }

    /**
     * 将date 转化成指定格式
     * @param date
     * @param strFormat
     * @return
     */
    public static String getDateformatString(Date date, String strFormat){
        SimpleDateFormat format = new SimpleDateFormat(strFormat);
        return format.format( date );
    }

    private static void setCalendarMonth( Calendar calendar, int month ){
        // 设置月
        switch ( month ){
            case 1:
                calendar.set( Calendar.MONTH, Calendar.JANUARY );
                break;
            case 2:
                calendar.set( Calendar.MONTH, Calendar.FEBRUARY );
                break;
            case 3:
                calendar.set( Calendar.MONTH, Calendar.MARCH );
                break;
            case 4:
                calendar.set( Calendar.MONTH, Calendar.APRIL );
                break;
            case 5:
                calendar.set( Calendar.MONTH, Calendar.MAY );
                break;
            case 6:
                calendar.set( Calendar.MONTH, Calendar.JUNE );
                break;
            case 7:
                calendar.set( Calendar.MONTH, Calendar.JULY );
                break;
            case 8:
                calendar.set( Calendar.MONTH, Calendar.AUGUST );
                break;
            case 9:
                calendar.set( Calendar.MONTH, Calendar.SEPTEMBER );
                break;
            case 10:
                calendar.set( Calendar.MONTH, Calendar.OCTOBER );
                break;
            case 11:
                calendar.set( Calendar.MONTH, Calendar.NOVEMBER );
                break;
            case 12:
                calendar.set( Calendar.MONTH, Calendar.DECEMBER );
                break;
            default:
                throw new BizException("月份异常");
        }
    }

    /**
     * 获取年月（yyyy-MM）
     * @return
     */
    public static String getYearMonth(int year, int month){
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        // 设置年
        calendar.set( Calendar.YEAR, year );
        // 设置月
        setCalendarMonth( calendar, month );

        return simpleDateFormatyyyyMM.format( calendar.getTime() );
    }

    /**
     * 获取年（yyyy）
     * @return
     */
    public static String getYear(int year){
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        // 设置年
        calendar.set( Calendar.YEAR, year );

        return simpleDateFormatyyyy.format( calendar.getTime() );
    }

    /**
     * 获取月（MM）
     * @return
     */
    public static String getMonth(int month){
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        // 设置月
        setCalendarMonth( calendar, month );

        return simpleDateFormatMM.format( calendar.getTime() );
    }

    /**
     * 获取指定年月的开始时间
     * @param year
     * @param month
     * @return
     */
    public static Date getYearMonthStartTime(int year, int month){
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        // 设置年
        calendar.set( Calendar.YEAR, year );
        // 设置月
        setCalendarMonth( calendar, month );
        // 设置指定月份的第一天
        calendar.set( Calendar.DAY_OF_MONTH, 1 );
        // 设置时
        calendar.set( Calendar.HOUR_OF_DAY, 0 );
        // 设置分
        calendar.set( Calendar.MINUTE, 0 );
        // 设置秒
        calendar.set( Calendar.SECOND, 0 );

        Date start = calendar.getTime();

        return start;
    }

    /**
     * 获取指定年月的结束时间
     * @param year
     * @param month
     * @return
     */
    public static Date getYearMonthEndTime(int year, int month){
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        // 设置年
        calendar.set( Calendar.YEAR, year );
        // 设置月
        setCalendarMonth( calendar, month );
        // 设置指定月份的最后一天
        calendar.set( Calendar.DATE, calendar.getActualMaximum( Calendar.DATE ) );
        // 设置时
        calendar.set( Calendar.HOUR_OF_DAY, 23 );
        // 设置分
        calendar.set( Calendar.MINUTE, 59 );
        // 设置秒
        calendar.set( Calendar.SECOND, 59 );

        Date end = calendar.getTime();

        return end;
    }

    /**
     * 获取指定日期距今 X年X月
     * @param date
     * @return
     */
    public static String yearCompare(Date date){
        DateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date fromDate = date;
        Date toDate = new Date();
        Calendar from = Calendar.getInstance();
        from.clear();
        from.setTime(fromDate);
        Calendar to = Calendar.getInstance();
        to.clear();
        to.setTime(toDate);

        int fromYear = from.get(Calendar.YEAR);
        int fromMonth = from.get(Calendar.MONTH);
        int fromDay = from.get(Calendar.DAY_OF_MONTH);

        int toYear = to.get(Calendar.YEAR);
        int toMonth = to.get(Calendar.MONTH);
        int toDay = to.get(Calendar.DAY_OF_MONTH);
        int year = toYear  -  fromYear;
        int month = toMonth  - fromMonth;
        int day = toDay  - fromDay;

        //按照减法原理，先day相减，不够向month借；然后month相减，不够向year借；最后year相减。
        Calendar now = Calendar.getInstance();
        now.clear();
        if (day <0) {
            month -=1;
            now.add(Calendar.MONTH, -1);//得到上一个月，用来得到上个月的天数。
            day = day + now.getActualMaximum(Calendar.DAY_OF_MONTH);
        }

        if (month <0) {
            month = (month +12) %12;
            year--;
        }

        StringBuffer age =new StringBuffer();
        if (year >0) {
            age.append(year +"年");
        }

        if (month >0) {
            age.append(month +"个月");
        }

        // if (day >0) {
        //  age.append(day +"天");
        // }

        if (year ==0 && month ==0 && day ==0) {
            age.append("今日出生");
        }

        return String.valueOf(age);
    }

    /**
     * 字符串转date
     */
    public static Date stringToDateAll(String str) throws ParseException {
        Date date = sdf.parse( str );
        return date;
    }


    /**
     * 字符串转date
     * @param yyyyMMdd
     * @return
     */
    public static Date stringToDate(String yyyyMMdd) throws ParseException {
        Date date = simpleDateFormatyyyyMMdd.parse( yyyyMMdd );
        return date;
    }

    /**
     * 获取传入时间的开始时间 如：yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static Date dayStartTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取传入时间的开始时间 如：yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static Date dayStartTime2(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取传入时间的结束时间 如：yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static Date dayEndTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);
        return calendar.getTime();
    }

    /**
     * 获取传入时间的结束时间 如：yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static Date dayEndTime2(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(date);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }

    /**
     * 获取传入时间的月开始时间 如：yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static Date monthStartTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(date);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取传入时间的月结束时间 如：yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static Date monthEndTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(date);
        calendar.add(Calendar.MONTH, 1);
        calendar.set(Calendar.DAY_OF_MONTH, 0);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }

    /**
     * 获取传入时间的-年-开始时间 如：yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static Date yearStartTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH, 0);
        calendar.set(Calendar.DAY_OF_MONTH, 1);
        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);
        return calendar.getTime();
    }

    /**
     * 获取传入时间的-年-结束时间 如：yyyy-MM-dd HH:mm:ss
     * @param date
     * @return
     */
    public static Date yearEndTime(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.clear();
        calendar.setTime(date);
        calendar.set(Calendar.MONTH, 11);
        calendar.set(Calendar.DAY_OF_MONTH, 31);
        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        return calendar.getTime();
    }

    public static Date getPreviousMonthLastDate() {
        Calendar calendar = Calendar.getInstance();
        // 上个月
        calendar.add(Calendar.MONTH, -1);
        // 上个月最后一天
        calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        return calendar.getTime();
    }

    /**
     * 格式化时间 返回字符串
     */
    public static String dateFormat(Date date, String formatStr){
        if( date == null ){
            return null;
        }
        if( StringUtils.isEmpty( formatStr ) ){
            return null;
        }
        SimpleDateFormat dateFormat = new SimpleDateFormat( formatStr );
        return dateFormat.format(date);
    }

    /**
     * 获取昨天的15:30:00
     */
    public static Date getYesterDay330(){
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -1);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(calendar.getTime()) + " 15:30:00");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取昨天的yyyyMMdd
     */
    public static String getYesterDayyyMMdd(){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyMMdd");
        return dateFormat.format( calendar.getTime() );
    }

    /**
     * 获取昨天的 yyyy-MM-dd
     */
    public static String getYesterDayyyyyMMdd(){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return dateFormat.format( calendar.getTime() );
    }

    /**
     * 获取昨天的 yyyy-MM-dd HH:mm:ss
     */
    public static String getYesterDayyyyyMMddHHmmss(){
        Calendar calendar = Calendar.getInstance();
        calendar.add(Calendar.DATE, -1);
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format( calendar.getTime() );
    }

    /**
     * 获取当前时间 yyyy-MM-dd HH:mm:ss
     */
    public static String getCurrentDayyyyyMMddHHmmss(){
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return dateFormat.format( calendar.getTime() );
    }

    /**
     * 获取当前时间 yyyy-MM-dd
     */
    public static String getCurrentDayyyyyMMdd(){
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        return dateFormat.format( calendar.getTime() );
    }

    /**
     * 获取当前时间， yyyy-MM-dd hh:mm:ss
     */
    public static Date getCurrent(){
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return sdf.parse( dateFormat.format( new Date() ) );
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取当前时间的第一天， yyyy-MM-dd hh:mm:ss
     */
    public static Date getCurrentFirstDay(){
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM");
            return sdf.parse( dateFormat.format( new Date() ) +"-01 00:00:00" );
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取今天的15:29:59
     * * @return
     */
    public static Date getToDay330() {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(new Date()) + " 15:29:59");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取昨天的16:30:00
     * * @return
     */
    public static Date getYesterDay1630(){
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -1);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(calendar.getTime()) + " 16:30:00");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取今天的16:29:59
     * * @return
     */
    public static Date getToDay1630() {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(new Date()) + " 16:29:59");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取昨天的08:09:59
     * * @return
     */
    public static Date getYesterDay0809(){
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -1);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(calendar.getTime()) + " 08:09:59");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取今天的08:10:00
     * * @return
     */
    public static Date getToDay0810() {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(new Date()) + " 08:10:00");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取昨天的08:14:59
     * * @return
     */
    public static Date getYesterDay0815(){
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -1);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(calendar.getTime()) + " 08:14:59");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取今天的08:15:00
     * * @return
     */
    public static Date getToDay0815() {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(new Date()) + " 08:15:00");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }


    /**
     * 获取昨天的08:49:59
     * * @return
     */
    public static Date getYesterDay0849(){
        try {
            Calendar calendar = Calendar.getInstance();
            calendar.add(Calendar.DATE, -1);
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(calendar.getTime()) + " 08:49:59");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 获取今天的08:50:00
     * * @return
     */
    public static Date getToDay0850() {
        try {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
            return sdf.parse(dateFormat.format(new Date()) + " 08:50:00");
        }catch (ParseException e){
            e.printStackTrace();
        }
        return null;
    }

    /**
     * 分钟转换为 *天*时*分
     */
    public static String minuteConvertString( Integer minute ){
        if( minute == null ){
            return "0分钟";
        }
        if( minute <= 0 ){
            return "0分钟";
        }
        int days = minute / 1440;
        int hours = minute % 1440 / 60;
        int minutes = minute % 60;
        String result = "";
        if( days > 0 ){
            result = result + days + "天";
        }
        if( hours > 0 ){
            result = result + hours + "小时";
        }
        if( minutes > 0 ){
            result = result + minutes + "分钟";
        }
        return result;
    }

    /**
     * 计算两个日期间隔的差
     * @param startDate
     * @param endDate
     * @return
     */
    public static Long getDateBetween( Date startDate, Date endDate, ChronoUnit differ ){
        if( startDate == null ){
            return null;
        }
        if( endDate == null ){
            return null;
        }
        if( differ == null ){
            return null;
        }

        // 开始时间
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String formattedStartDate = formatter.format( startDate );
        LocalDate startLocalDate = LocalDate.parse( formattedStartDate );

        // 结束时间
        String formattedEndDate = formatter.format( endDate );
        LocalDate endLocalDate = LocalDate.parse( formattedEndDate );

        switch ( differ ){
            // 分钟
            case MINUTES:
                return ChronoUnit.MINUTES.between( startLocalDate, endLocalDate );
            // 小时
            case HOURS:
                return ChronoUnit.HOURS.between( startLocalDate, endLocalDate );
            // 天
            case DAYS:
                return ChronoUnit.DAYS.between( startLocalDate, endLocalDate );
            // 月
            case MONTHS:
                return ChronoUnit.MONTHS.between( startLocalDate, endLocalDate );
            // 年
            case YEARS:
                return ChronoUnit.YEARS.between( startLocalDate, endLocalDate );
            default:
                throw new BizException("未知类型");
        }

    }

    /**
     * 计算两个时间的分钟差
     * @param startDate
     * @param endDate
     * @return
     */
    public static Long getDateBetweenMinutes( Date startDate, Date endDate ){
        long diff = endDate.getTime() - startDate.getTime();
        long minutes = diff / ( 60 * 1000 );
        return minutes;
    }

    /**
     * 根据 long 转 date
     */
    public static Date longFormatDate( long timestamp ){
        Instant instant = Instant.ofEpochMilli( timestamp );
        return Date.from(instant);
    }

    /**
     * 根据 Integer 转 date
     */
    public static Date integerFormatDate( Integer timestamp ) {
        return new Date(timestamp * 1000L);
    }

    public static void main(String arg[]) throws ParseException {
        Instant instant = Instant.now();
        long unixTimestamp = instant.getEpochSecond();

        System.out.println( unixTimestamp );

        System.out.println( getUnix( new Date() ) );

        String timeString = "2024-10-01T00:00:00Z";
        DateTimeFormatter formatter = DateTimeFormatter.ISO_INSTANT;
        Instant instant_ = Instant.from( formatter.parse( timeString ) );

        System.out.println( instant_.getEpochSecond() );
    }

    /**
     * 指定Date减一秒
     */
    public static Date subtractOneSecond(Date date){
        Calendar calendar = Calendar.getInstance();
        calendar.setTime( date );
        calendar.add( Calendar.SECOND, -1 );
        return calendar.getTime();
    }

    /**
     * 获取两个时间节点之间的 yyyy-MM 列表集合
     */
    public static List<String> getMonthBetween(Date startDate, Date endDate){
        List<String> result = new ArrayList<>();
        try {
            String strStartDate = DateHelper.dateFormat( startDate, "yyyy-MM" );
            String strEndDate = DateHelper.dateFormat( endDate, "yyyy-MM" );

            Calendar min = Calendar.getInstance();
            Calendar max = Calendar.getInstance();

            min.setTime( simpleDateFormatyyyyMM.parse( strStartDate ) );
            min.set( min.get( Calendar.YEAR ), min.get( Calendar.MONTH ), 1 );

            max.setTime( simpleDateFormatyyyyMM.parse( strEndDate ) );
            max.set( max.get( Calendar.YEAR ), max.get( Calendar.MONTH ), 2 );

            Calendar curr = min;

            while ( curr.before( max ) ){
                result.add( simpleDateFormatyyyyMM.format( curr.getTime() ) );
                curr.add( Calendar.MONTH, 1 );
            }
        } catch (Exception e){
        }
        return result;
    }
}
